###############################################################################
# FileName      : do_parted.sh
# Description   : parted all disks for ceph OSD
# Author        ：fanxiaoguang(fanxiaoguang@zettakit.com/solar_ambitious@126.com)
# Date          : 2016/03/31
###############################################################################

#!/bin/bash

set -e
if [ ! -x "/sbin/parted" ]; then
    echo "This script requires /sbin/parted to run!" >&2
    exit 1
fi

str=$1
str=${str//,/ };
arr=($str);


for i in ${arr[@]};do
    echo "Creating partitions on /dev/${i} ..."
    parted -a optimal --script /dev/${i} -- mktable gpt
    sleep 1
    parted -a optimal --script /dev/${i} -- mkpart primary xfs 0% 100%
    sleep 1
    echo "Formatting xfs /dev/${i}1 ..."
    mkfs.xfs -f /dev/${i}1 &
done

exit
SSDS="l m"
for i in ${SSDS}; do
    parted -s /dev/sd${i} mklabel gpt
    echo "parted /dev/sd${i}1 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 0% 10%
    echo "parted /dev/sd${i}2 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 11% 20%
    echo "parted /dev/sd${i}3 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 21% 30%
    echo "parted /dev/sd${i}4 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 31% 40%
    echo "parted /dev/sd${i}5 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 41% 50%
    echo "parted /dev/sd${i}6 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 51% 60%
    echo "parted /dev/sd${i}7 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 61% 70%
    echo "parted /dev/sd${i}8 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 71% 80%
    echo "parted /dev/sd${i}9 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 81% 90%
    echo "parted /dev/sd${i}10 ..."
    sleep 1
    parted -s /dev/sd${i} mkpart primary 91% 100%
done
